<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="vue.js"></script>
</head>
<body>
    <div id="app">
        <p>总价格：{{totalPrice}}</p>
        <p>单价：{{price}}</p>
        <p>数量：{{num}}</p>
        <div>
            <button @click="num == 0 ? 0 : num--">数量减少</button>
            <button @click='num++'>数量增加</button>
        </div>
    </div>
    <script>
        var vm = new Vue({
            el:'#app',
            data:{
                price:20,
                num:0
            },
            computed:{
                // 总价格totalPrice
                totalPrice () {
                    return this.price * this.num
                }
            }
        })
    </script>
</body>
</html>